<!doctype html>
<html lang="zh-CH">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
	<title>木投网--个人中心--账户信息</title>
	<link rel="stylesheet" href="/resource/css/mt_index.css">
	<link rel="stylesheet" href="/resource/css/mt_user.css">
	<link rel="stylesheet" href="/resource/css/mt_showBo.css">
</head>
<body>
@include("common.shop_user_head")
		<div class="user-cont left">
			<div class="user-title">账户信息</div>
			<div class="account">
				<div class="user-img left">
					<div class="img">
						<div class="form-img"><img src="{{session_get(UserEnum::USER_INFO_SESSION_KEY)->avatar}}" alt=""></div>
						<input type="hidden" value="{{session_get(UserEnum::USER_INFO_SESSION_KEY)->avatar}}" id="old_avatar">
						<span id="file-acc">上传
							<input type="file"  name="file" accept="image/*"/>
						</span>
					</div>
				</div>
				<div class="form-account left">
						<div class="form-group">
							<label for="">账户：</label>
							<div class="form-control">{{session_get(UserEnum::USER_INFO_SESSION_KEY)->mobile}}</div>
						</div>
						<div class="form-group">
							<label for="">姓名：</label>
							<input type="text" class="form-control" placeholder="" value="{{session_get(UserEnum::USER_INFO_SESSION_KEY)->user_name}}" onblur="check_username()" id="username" >
							<span id="t_username">不能为空</span>
						</div>
						<div class="form-group">
							<label for="">联系电话：</label>
							<input type="text" class="form-control" placeholder="" value="@if(empty(session_get(UserEnum::USER_INFO_SESSION_KEY)->phone)){{session_get(UserEnum::USER_INFO_SESSION_KEY)->mobile}}@else{{session_get(UserEnum::USER_INFO_SESSION_KEY)->phone}}@endif" id="phone">
						</div>
						<div class="form-group">
							<label for="">公司：</label>
							<input type="text" class="form-control" placeholder="" value="{{session_get(UserEnum::USER_INFO_SESSION_KEY)->corporation}}" id="corporation" onblur="check_corporation()"  name="corporation">
							<span id="t_corporation">不能为空</span>
						</div>
						<div class="form-group">
							<label for="">地址：</label>
							<input type="text" class="form-control" value="{{session_get(UserEnum::USER_INFO_SESSION_KEY)->address}}" id="address">
						</div>
						<button type="button" class="btn-login btn-file J_btn">保 存</button>
				</div>
			</div>
		</div>
@include("common.shop_user_foot")
<div id="file_token" class="hide">{{$token}}</div>
<script src="/resource/js/jquery-1.11.3.min.js"></script>
<script src="/resource/js/mt_index.js"></script>
<script src="/resource/js/mt_showBo.js"></script>  <!-- 提示信息 -->
<script src="/resource/js/webuploader.html5only.min.js"></script>
<script src="/resource/js/diyUpload.js"></script>
<script>
	$('#file-acc').click(function(){
		if(typeof FileReader =='undefined'){
			alert('亲,您的浏览器还不支持HTML5的FileReader接口,请更新浏览器或者使用谷歌浏览器获得最好体验');
		}
	});
	var toKen = $('#file_token').html();
	$('#file-acc').diyUpload({
		success:function( data ) {
			var imgSrc = "http://picture.mutouw.com/"+data.key;
			var user_name = $("#username").val();
			var phone = $("#phone").val();
			var corporation = $("#corporation").val();
			var address = $("#address").val();
			$.ajax({
				url: "/user_account_modify",
				type: "POST",
				data: "user_name=" + user_name +"&phone="+phone+"&corporation="+corporation+"&address="+address+'&avatar='+imgSrc,
				success: function (msg) {
					if(msg){
						Showbo.Msg.wait('<img class="left" src="/resource/img/reg_success.png" alt=""><span class="left">修改成功</span><div class="close">关闭</div>');
						$('#dvMsgBox .close').show();
					}
				}
			})
		},
		error:function( err ) {
			console.log( err );
		},
		fileNumLimit:1,
		buttonText : '上传',
	});
	$(document).delegate('.J_btn','click',function(){
		var imgSrc = $('#old_avatar').val();
		var user_name = $("#username").val();
		var phone = $("#phone").val();
		var corporation = $("#corporation").val();
		var address = $("#address").val();
		$.ajax({
			url: "/user_account_modify",
			type: "POST",
			data: "user_name=" + user_name +"&phone="+phone+"&corporation="+corporation+"&address="+address+'&avatar='+imgSrc,
			success: function (msg) {
				if(msg){
					Showbo.Msg.wait('<img class="left" src="/resource/img/reg_success.png" alt=""><span class="left">修改成功</span><div class="close">关闭</div>');
					$('#dvMsgBox .close').show();
				}
			}
		})
	});

	function check_username() {
		var username = $('#username').val();
		if (username){
			$("#t_username").hide();
			$('.btn-login').removeClass('btn-black');
			return true
		} else {
			$("#t_username").show();
			$('.btn-login').addClass('btn-black');
			return false
		}
	}

	function check_corporation() {
		var corporation = $('#corporation').val();
		if (corporation){
			$("#t_corporation").hide();
			$('.btn-login').removeClass('btn-black');
			return true
		} else {
			$("#t_corporation").show();
			$('.btn-login').addClass('btn-black');
			return false
		}
	}

	function check_all(){
		if(check_corporation()&&check_username()){
			Showbo.Msg.wait('<img class="left" src="/resource/img/reg_success.png" alt=""><span class="left">修改成功</span><div class="close">关闭</div>');
			$('#dvMsgBox .close').show();
			return true
		}else{
			return  false
		}

	}


</script>
</body>
</html>